var e = getApp(), a = e.requirejs("core"), t = e.requirejs("wxParse/wxParse"), i = e.requirejs("biz/diypage"), s = e.requirejs("jquery");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths:[],
    check:true,
    content:'',
    pid:'',
    bid:'',
    rpid:''
  },
  QueryParams:{
    bid:'',
    pid:'',
    content:'',
    rpid:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  TimeId:-1,
  bindInput(e){
    // console.log(e);
    let content=e.detail.value
    this.setData({
      content
    })
    // console.log(this.data.content);
    clearTimeout(this.TimeId)
    this.TimeId=setTimeout(() => {
      // this.getreplay(this.data.bid,this.data.pid,this.data.rpid,this.data.content)
    }, 500);
    },
  // onLoad: function (options) {
  //  console.log(options);
  //  this.QueryParams.pid = options.id
  // },
  onShow:function(){
    // console.log(this.data.cid);
    let bid=wx.getStorageSync('bid')
    let pid=wx.getStorageSync('pid')
    
    // console.log(bid);
    // let title 
    this.setData({
     bid,
     pid
    })
    
    // console.log(this.data.pid);
    // this.getreplay(this.data.bid,this.data.pid,this.data.rpid,this.data.content)
  },
  // 调用相册方法
  chooseImage(){
    // console.log(11);
   const that = this
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const imagePath = res.tempFilePaths
        let tempFilePaths= that.data.tempFilePaths.concat(imagePath)
        that.setData({
          tempFilePaths
        })
      }
    })
  },

  // 点击打开图片选项卡
  checkimg(){
   let check=!this.data.check
   console.log(check);
   this.setData({
    check
   })
  },
  // 删除图片
  canlimg(){
    let index = e.currentTarget.dataset.id
   let image = this.data.tempFilePaths
  //  console.log(e,index,image);
   image.splice(index,1)
    this.setData({
      tempFilePaths:image
    })
  },
  // 数据
  getreplay(bid,pid,rpid,content){
    a.post('sns/board_reply',{bid,pid,rpid,content},(res) => {
      if(res.status==1){
        // 返回上一个页面
        wx.navigateBack({})
      }else{
        wx.showToast({
          title: '未找到话题',
          icon:'none'
        })
      }
    })
  },
  //  发表文章
submithandle(){
  this.getreplay(this.data.bid,this.data.pid,this.QueryParams.rpid,this.data.content)
  // console.log(this.data.bid,this.QueryParams.pid,this.data.content)
},

})